<?php
App::uses('AppController', 'Controller');
/**
 * AnimesGenres Controller
 *
 * @property AnimesGenre $AnimesGenre
 */
class AnimesGenresController extends AppController {

/**
 * Indexs method
 *
 * @return void
 */
	public function index() {
		$this->AnimesGenre->recursive = 0;
		$this->set('animesGenres', $this->paginate());
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->AnimesGenre->exists($id)) {
			throw new NotFoundException(__('Invalid animes genre'));
		}
		$options = array('conditions' => array('AnimesGenre.' . $this->AnimesGenre->primaryKey => $id));
		$this->set('animesGenre', $this->AnimesGenre->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->AnimesGenre->create();
			if ($this->AnimesGenre->save($this->request->data)) {
				$this->Session->setFlash(__('The animes genre has been saved'));
				$this->redirect(array('action' => 'Indexs'));
			} else {
				$this->Session->setFlash(__('The animes genre could not be saved. Please, try again.'));
			}
		}
		$animes = $this->AnimesGenre->Anime->find('list');
		$genres = $this->AnimesGenre->Genre->find('list');
		$this->set(compact('animes', 'genres'));
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		if (!$this->AnimesGenre->exists($id)) {
			throw new NotFoundException(__('Invalid animes genre'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->AnimesGenre->save($this->request->data)) {
				$this->Session->setFlash(__('The animes genre has been saved'));
				$this->redirect(array('action' => 'Indexs'));
			} else {
				$this->Session->setFlash(__('The animes genre could not be saved. Please, try again.'));
			}
		} else {
			$options = array('conditions' => array('AnimesGenre.' . $this->AnimesGenre->primaryKey => $id));
			$this->request->data = $this->AnimesGenre->find('first', $options);
		}
		$animes = $this->AnimesGenre->Anime->find('list');
		$genres = $this->AnimesGenre->Genre->find('list');
		$this->set(compact('animes', 'genres'));
	}

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		$this->AnimesGenre->id = $id;
		if (!$this->AnimesGenre->exists()) {
			throw new NotFoundException(__('Invalid animes genre'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->AnimesGenre->delete()) {
			$this->Session->setFlash(__('Animes genre deleted'));
			$this->redirect(array('action' => 'Indexs'));
		}
		$this->Session->setFlash(__('Animes genre was not deleted'));
		$this->redirect(array('action' => 'Indexs'));
	}
}
